﻿

namespace MyCoreLib.UnitTest.Data.Common
{
    using System;
    using System.Data;
    using System.Data.Fakes;

    using Microsoft.VisualStudio.TestTools.UnitTesting;

    using MyCoreLib.Data.Common;
    using MyCoreLib.Data.Common.Fakes;


    [TestClass]
    public class DbClientObject_BeginTransaction_Should
    {
        [TestMethod]
        public void OpenInnerConnectionIfNotOpenedYet()
        {
            bool isOpen = false;
            var connection = new StubIDbConnection
                                 {
                                     Open = () => isOpen = true,
                                     BeginTransaction = () => new StubIDbTransaction()
                                 };
            var client = new StubDbClientObject(connection);            
            client.CreateTransactionObjectIDbTransaction = (dbt) => new StubDbTransactionObject(client, dbt);
            using (var transaction = client.BeginTransaction())
            {
                Assert.IsTrue(isOpen, "The connection should be opened");
            }
        }
    }
}
